package com.ellricky.baselib.ui.task.beike;

import android.view.View;

import com.andr.common.http.callback.JOCallback;
import com.andr.common.ui.activity.BaseToolBarActivity;
import com.andr.common.ui.mvp.BasePresenter;
import com.andr.common.util.EmptyUtil;
import com.andr.common.util.ToastUtil;
import com.ellricky.baselib.BaseConstant;
import com.ellricky.baselib.R;
import com.ellricky.baselib.http.HttpUtils;
import com.ellricky.baselib.util.EAppUtil;
import com.ellricky.baselib.widget.EditItemView;
import com.flyco.roundview.RoundTextView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import static com.ellricky.baselib.http.Api.API_PRE_LESSON_SAVE;


public class PreLessonSaveActivity extends BaseToolBarActivity<Void, BasePresenter<Void>> {

    private EditItemView etContent;
    private RoundTextView btnSubmit;

    private String classId;
    private String openDate;

    @Override
    public int getContentLayout() {
        return R.layout.base_activity_pre_lesson_save;
    }

    @Override
    protected void initUIView() {
        super.initUIView();
        classId = getIntent().getStringExtra("classId");
        openDate = getIntent().getStringExtra("openDate");
        mTvTitle.setText(R.string.base_pre_lesson);

        etContent = findViewById(R.id.etContent);
        btnSubmit = findViewById(R.id.btnSubmit);

        btnSubmit.setOnClickListener(this);
    }

    @Override
    protected void onClickView(View v) {
        super.onClickView(v);
        if (v == btnSubmit) postSubmit();
    }

    private void postSubmit() {
        String courseInfo = etContent.getValue();
        if (EmptyUtil.isEmpty(courseInfo)) {
            ToastUtil.show(this, R.string.base_pre_lesson_hint);
            return;
        }

        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("classId",classId);
        paramMap.put("courseInfo",courseInfo);
        paramMap.put("openDate",openDate);

        String url = EAppUtil.getApiHost() + API_PRE_LESSON_SAVE;
        HttpUtils.getInstance().post(url, paramMap, new  JOCallback(this) {
            @Override
            protected void onSuccess(JSONObject jsonObject, String s) {
                setResult(BaseConstant.RESULT_CODE_ADD);
                finish();
            }

        });

    }
}

